package idv.loveloser.dao;

import java.util.List;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.criterion.Example;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * A data access object (DAO) providing persistence and search support for
 * MdlEnrolPaypal entities. Transaction control of the save(), update() and
 * delete() operations can directly support Spring container-managed
 * transactions or they can be augmented to handle user-managed Spring
 * transactions. Each of these methods provides additional information for how
 * to configure it for the desired type of transaction control.
 * 
 * @see idv.loveloser.dao.MdlEnrolPaypal
 * @author MyEclipse Persistence Tools
 */

public class MdlEnrolPaypalDAO extends BaseHibernateDAO {
	private static final Logger log = LoggerFactory
			.getLogger(MdlEnrolPaypalDAO.class);
	// property constants
	public static final String BUSINESS = "business";
	public static final String RECEIVER_EMAIL = "receiverEmail";
	public static final String RECEIVER_ID = "receiverId";
	public static final String ITEM_NAME = "itemName";
	public static final String COURSEID = "courseid";
	public static final String USERID = "userid";
	public static final String INSTANCEID = "instanceid";
	public static final String MEMO = "memo";
	public static final String TAX = "tax";
	public static final String OPTION_NAME1 = "optionName1";
	public static final String OPTION_SELECTION1_X = "optionSelection1X";
	public static final String OPTION_NAME2 = "optionName2";
	public static final String OPTION_SELECTION2_X = "optionSelection2X";
	public static final String PAYMENT_STATUS = "paymentStatus";
	public static final String PENDING_REASON = "pendingReason";
	public static final String REASON_CODE = "reasonCode";
	public static final String TXN_ID = "txnId";
	public static final String PARENT_TXN_ID = "parentTxnId";
	public static final String PAYMENT_TYPE = "paymentType";
	public static final String TIMEUPDATED = "timeupdated";

	public void save(MdlEnrolPaypal transientInstance) {
		log.debug("saving MdlEnrolPaypal instance");
		try {
			getSession().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(MdlEnrolPaypal persistentInstance) {
		log.debug("deleting MdlEnrolPaypal instance");
		try {
			getSession().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public MdlEnrolPaypal findById(java.lang.Long id) {
		log.debug("getting MdlEnrolPaypal instance with id: " + id);
		try {
			MdlEnrolPaypal instance = (MdlEnrolPaypal) getSession().get(
					"idv.loveloser.dao.MdlEnrolPaypal", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(MdlEnrolPaypal instance) {
		log.debug("finding MdlEnrolPaypal instance by example");
		try {
			List results = getSession()
					.createCriteria("idv.loveloser.dao.MdlEnrolPaypal")
					.add(Example.create(instance)).list();
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding MdlEnrolPaypal instance with property: "
				+ propertyName + ", value: " + value);
		try {
			String queryString = "from MdlEnrolPaypal as model where model."
					+ propertyName + "= ?";
			Query queryObject = getSession().createQuery(queryString);
			queryObject.setParameter(0, value);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByBusiness(Object business) {
		return findByProperty(BUSINESS, business);
	}

	public List findByReceiverEmail(Object receiverEmail) {
		return findByProperty(RECEIVER_EMAIL, receiverEmail);
	}

	public List findByReceiverId(Object receiverId) {
		return findByProperty(RECEIVER_ID, receiverId);
	}

	public List findByItemName(Object itemName) {
		return findByProperty(ITEM_NAME, itemName);
	}

	public List findByCourseid(Object courseid) {
		return findByProperty(COURSEID, courseid);
	}

	public List findByUserid(Object userid) {
		return findByProperty(USERID, userid);
	}

	public List findByInstanceid(Object instanceid) {
		return findByProperty(INSTANCEID, instanceid);
	}

	public List findByMemo(Object memo) {
		return findByProperty(MEMO, memo);
	}

	public List findByTax(Object tax) {
		return findByProperty(TAX, tax);
	}

	public List findByOptionName1(Object optionName1) {
		return findByProperty(OPTION_NAME1, optionName1);
	}

	public List findByOptionSelection1X(Object optionSelection1X) {
		return findByProperty(OPTION_SELECTION1_X, optionSelection1X);
	}

	public List findByOptionName2(Object optionName2) {
		return findByProperty(OPTION_NAME2, optionName2);
	}

	public List findByOptionSelection2X(Object optionSelection2X) {
		return findByProperty(OPTION_SELECTION2_X, optionSelection2X);
	}

	public List findByPaymentStatus(Object paymentStatus) {
		return findByProperty(PAYMENT_STATUS, paymentStatus);
	}

	public List findByPendingReason(Object pendingReason) {
		return findByProperty(PENDING_REASON, pendingReason);
	}

	public List findByReasonCode(Object reasonCode) {
		return findByProperty(REASON_CODE, reasonCode);
	}

	public List findByTxnId(Object txnId) {
		return findByProperty(TXN_ID, txnId);
	}

	public List findByParentTxnId(Object parentTxnId) {
		return findByProperty(PARENT_TXN_ID, parentTxnId);
	}

	public List findByPaymentType(Object paymentType) {
		return findByProperty(PAYMENT_TYPE, paymentType);
	}

	public List findByTimeupdated(Object timeupdated) {
		return findByProperty(TIMEUPDATED, timeupdated);
	}

	public List findAll() {
		log.debug("finding all MdlEnrolPaypal instances");
		try {
			String queryString = "from MdlEnrolPaypal";
			Query queryObject = getSession().createQuery(queryString);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public MdlEnrolPaypal merge(MdlEnrolPaypal detachedInstance) {
		log.debug("merging MdlEnrolPaypal instance");
		try {
			MdlEnrolPaypal result = (MdlEnrolPaypal) getSession().merge(
					detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(MdlEnrolPaypal instance) {
		log.debug("attaching dirty MdlEnrolPaypal instance");
		try {
			getSession().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(MdlEnrolPaypal instance) {
		log.debug("attaching clean MdlEnrolPaypal instance");
		try {
			getSession().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}
}